import * as echarts from 'echarts'
export function pie(user_man, user_woman, element) {
  const myChart = echarts.init(element)
  const option = {
    tooltip: {
      trigger: 'item'
    },
    legend: {
      top: '5%',
      left: 'center'
    },

    series: [
      {
        name: '用户来源',
        type: 'pie',
        radius: ['40%', '70%'],
        avoidLabelOverlap: false,
        itemStyle: {
          borderRadius: 10,
          borderColor: '#fff',
          borderWidth: 2
        },
        label: {
          show: false,
          position: 'center'
        },
        emphasis: {
          label: {
            show: true,
            fontSize: 40,
            fontWeight: 'bold'
          }
        },
        labelLine: {
          show: false
        },
        data: [
          { value: user_man, name: '男性' },
          { value: user_woman, name: '女性' }
        ]
      }
    ]
  }

  myChart.setOption(option)
}

export function bar(data, element) {
  console.log(data)
  const myChart = echarts.init(element)
  const option = {
    xAxis: {
      type: 'category',
      data: data.map(item => item.catename)
    },
    yAxis: {
      type: 'value'
    },
    title: {
      // 图表标题大小
      text: '各分类文章发布数量',
      top: '2%',
      left: '20%',
      textStyle: {
        fontSize: 16,
        color: '#5c7bd9'
      }
    },
    series: [
      {
        data: data.map(item => item.num),
        type: 'bar',
        showBackground: true,
        backgroundStyle: {
          color: 'rgba(180, 180, 180, 0.2)'
        }
      }
    ]
  }

  myChart.setOption(option)
}
